//
//  SettingsWifiHotSpotListView.m
//  wAudioShare
//
//  Created by Anson on 15-1-22.
//  Copyright (c) 2015年 赵帅. All rights reserved.
//

#import "SettingsWifiHotSpotListView.h"

@interface SettingsWifiHotSpotListView () <UITableViewDataSource, UITableViewDelegate>

@property (strong, nonatomic) NSArray *dataList;
@property (strong, nonatomic) UITableView *listView;

@end

@implementation SettingsWifiHotSpotListView


- (instancetype)initWithFrame:(CGRect)frame dataSource:(id)aDataSrc {
    
    self = [super initWithFrame:frame];
    if (self) {
        
        self.layer.borderColor = [UIColor blackColor].CGColor;
        self.layer.borderWidth = 1.5;
        _dataList = aDataSrc;
        _listView = [[UITableView alloc] initWithFrame:frame style:UITableViewStylePlain];
        _listView.dataSource = self;
        _listView.delegate = self;
        _listView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
        [self addSubview:_listView];
    }
    return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

#pragma mark - TableView Delegate
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 44)];
    titleLabel.text = @"选择无线网络";
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.backgroundColor = [UIColor blackColor];
    titleLabel.textColor = [UIColor whiteColor];
    return titleLabel;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataList.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CELL"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CELL"];
    }
    
    cell.imageView.image = [UIImage imageNamed:@""];
    cell.textLabel.text = self.dataList[indexPath.row][@"ssid"];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(settingsWifiHotSpotListView:didSelectRowAtIndexPath:)]) {
        [self.delegate performSelector:@selector(settingsWifiHotSpotListView:didSelectRowAtIndexPath:) withObject:self withObject:indexPath];
    }
}

@end
